﻿using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UFIDA.U9.Cust.STR.PlugBE.Public
{
    public class JsonConfig
    {
        readonly string filePath = AppDomain.CurrentDomain.BaseDirectory + "APIBaseInfo.json";
        public JObject config;
        public JsonConfig()
        {
            ReadJsonFile();
        }

        public JsonConfig(string filePath)
        {
            this.filePath = filePath;
            ReadJsonFile();
        }

        private void ReadJsonFile()
        {
            using (System.IO.StreamReader file = System.IO.File.OpenText(filePath))
            {
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    config = (JObject)JToken.ReadFrom(reader);
                }
            }
        }

        public string SelectToken(string path)
        {
            return config.SelectToken(path)?.ToString() ?? "";
        }
    }
}
